const HtmlWebpackPlugin = require("html-webpack-plugin")


let entry = [
  {
    path: './src/pages/pc/2019/activity1/index.js',
    package: true,
    title: "首页",
    keywords: "123",
    description: "sdf"
  },
  {
    path: './src/pages/pc/2019/activity2/index.js',
    package: true
  }
]




module.exports = {
  entry: entry.filter(({package}) => package),
  chunkName (name) {
    return name.slice(12, -3)
  },
  // 创建入口
  createEntry() {
    return this.entry.reduce((entry, { path }) => {
      entry[this.chunkName(path)] = path
      return entry
    }, {})
  },
  // 创建模板
  createHtmlTemplate() {
    return this.entry.map(({path, title, keywords = '', description = ''}) => new HtmlWebpackPlugin({
      template: path.replace(/\.js$/, '.html'),
      filename: this.chunkName(path) + '.html',
      chunks: [this.chunkName(path)],
      title,
      meta: {
        keywords,
        description
      }
    }))
  }
}